# The Box Model

# The Box Model

The CSS box model is essentially a box that wraps around every HTML element. It consists of margin, border, padding, and the actual content.

image-20220111093829073

inline Elements ignore other inlineElements vertical padding

Margin collapse (opens new window): Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.


# box-sizing

How the total size of the box is calculated:

box-sizing: content-box

  • the default setting
  • width/height doesn't include margin, border & padding
  • width (height) = width(height) + padding + border

box-sizing: border-box.

  • include the padding and border in an element's total width and height.
  • Recommended (include in CSS reset)